package com.wz.dhs.controller.system;

import com.wz.dhs.model.common.PageInfo;
import com.wz.dhs.model.common.Result;
import com.wz.dhs.po.user.SysUserEntity;
import com.wz.dhs.service.base.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * 管理账号信息Controller
 *
 * @author ruoyi
 * @date 2023-09-20 21:51:41
 */
@RestController
@RequestMapping("/system/admin")
public class SysUserController {
    @Autowired
    private ISysUserService sysUserService;



    /**
     * 查询管理账号信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:admin:list')")
    @GetMapping("/list")
    public Result<PageInfo<SysUserEntity>> list(SysUserEntity sysUser) {
        PageInfo<SysUserEntity> list = sysUserService.selectSysUserList(sysUser);
        return Result.data(list);
    }

    /**
     * 获取管理账号信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:admin:query')")
    @GetMapping(value = "/{id}")
    public Result<SysUserEntity> getInfo(@PathVariable("id") Long id) {
        return Result.data(sysUserService.selectSysUserById(id));
    }

    /**
     * 新增管理账号信息
     */
    @PreAuthorize("@ss.hasPermi('system:admin:add')")
    @PostMapping
    public Result<String> add(@RequestBody SysUserEntity sysUser) {
        sysUserService.insertSysUser(sysUser);
        return Result.success("新增成功");
    }

    /**
     * 修改管理账号信息
     */
    @PreAuthorize("@ss.hasPermi('system:admin:edit')")
    @PutMapping
    public Result<String> edit(@RequestBody SysUserEntity sysUser) {
        sysUserService.updateSysUser(sysUser);
        return Result.success("修改成功");
    }

    /**
     * 删除管理账号信息
     */
    @PreAuthorize("@ss.hasPermi('system:admin:remove')")
    @DeleteMapping("/{ids}")
    public Result<String> remove(@PathVariable Long[] ids) {
        sysUserService.deleteSysUserByIds(ids);
        return Result.success("删除成功");
    }
}
